<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/1.4.8/angular.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
    <div>
        <span>{{result}}</span>
        <!--<span>{{result.name}}</span>
        <span>{{result.age}}</span>
        <span>{{result.sex}}</span>-->
    </div>
    <button ng-click="send()">send</button>
</div>
<script type="application/javascript">
    var app = angular.module("app", []);
    // 1：调用config方法，注入$httpProvider服务，并调用该服务对象分别重置发送数据时默认函数transformRequest
    // 和属性Content-type的值。

    // 2:在重置transformRequest函数时，对HTTP发送体内容进行转码，并对转码后的内容进行序列化操作，
    // 便于发送时的数据传输和服务端的接受
    app.config(function ($httpProvider) {
        $httpProvider.defaults.headers.post = {
            'Content-type':'application/x-www-form-urlencoded'
        }
        $httpProvider.defaults.transformRequest = function (obj) {
            var arrStr = [];
            for(var p in obj){
                arrStr.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            }
            return arrStr.join("&");
        }
    });

    app.controller("myCtrl", ["$scope", "$http", function ($scope, $http) {
        $scope.result = "";
        $scope.send = function () {
            $http.post('http://localhost:8081/open/payment/testAngularPost.action',{'name':'JJ'})
                    .success(function (data, status, headers, config) {
                        $scope.result = data;
                        console.log("status:" + status);
                        console.log("headers:" + headers);
                        console.log("config:" + config);
                    })
        };
    }]);
</script>
</body>
</html>